<#include '/pages/taglib/core.ftl'>
<#include '/pages/taglib/common.ftl'>
<#include '/pages/taglib/container.ftl'>

<#if !modelPrivilege?exists>
	<#assign modelPrivilege = false>
</#if>
<div id="fieldPermissionCtn" style="min-height: 20px;padding-left: 10px;clear:both">
<style>
	.fieldPrivlegeList {
		float: left;
		width: 500px;
		margin-top: 4px;
	}
	.fieldPrivlegeList.editable td {
		height: 21px;
		padding-left: 4px;
	}
	.fieldTip {
		color: #666666;
	}
</style>

<#assign imagePathPrefix = base + '/static/espirit'>
<@script src="/static/espirit/scripts/espirit/eap/sa/privilege.js"/>
<script>
	when('eap_sa_privilege', function() {
		eap_sa_privilege.init('${modelPrivilege?string}');
	});
</script>

<form id="userFiedPermissionForm" action="${fn.link('/espirit/eap/sa/loginUser.updateFieldPermission.html')}" method="post">
<#if modelPrivilege == true>
	<#assign ctnLabel = action.getText('model.espirit.eap.sa.user.modelFieldPermission')>
<#else>
	<#assign ctnLabel = action.getText('model.espirit.eap.sa.user.fieldPermission')>
</#if>
<@container label=ctnLabel>
	<@select name="category" collection=categoryOptions label="common.category" property="key" labelProperty="value"/>
	<@select name="model" collection=modelOptions label="common.entity" property="key" labelProperty="value"/>
	<#if !modelPrivilege>
		<@select name="method" collection=methodOptions label="common.method" property="key" labelProperty="value"/>
	</#if>
	
	<@hidden name="userId"/>
	<@hidden name="modelPrivilege"/>
</@container>

<table class="tablelist editable fieldPrivlegeList">
	<thead>
		<tr>
			<th width='320px'><div class="th"><div class="label"><@i18n name='字段名'/></div></div></th>
			<th width='60px'><div class="th"><div class="label"><@i18n name='隐藏'/></div></div></th>
			<th width='60px'><div class="th"><div class="label"><@i18n name='查看'/></div></div></th>
			<th width='60px'><div class="th"><div class="label"><@i18n name='编辑'/></div></div></th>
		</tr>
	</thead>
	<tbody>
	
	<#if method?? && method?starts_with('search') && !modelPrivilege>
		<#assign isSearchMethod = true>
	<#else>
		<#assign isSearchMethod = false>
	</#if>
	<#if fieldPermissions?exists && fieldPermissions?size gt 0>
	<#list fieldPermissions as fieldPermission>
		<tr>
			<td>
				<#if isSearchMethod>
					<span class="fieldTip">				
					<#if fieldPermission.fieldName?starts_with('model.')>
						<@i18n name='action.search'/> - 
					<#elseif fieldPermission.fieldName?starts_with('execute.')>
						<@i18n name='common.list'/> - 
					<#elseif fieldPermission.fieldName?starts_with('advanceModel.')>
						<@i18n name='common.advancedSearch'/> - 
					</#if>
					</span>
				<#else>
					<#if fieldPermission.fieldName?starts_with('advanceModel.')>
						<@i18n name='common.advancedSearch'/> - 
					</#if>
				</#if>
				<@i18n name=fieldPermission.fieldNameLabel/>
				<@hidden name='fieldPermissions[' + fieldPermission_index + '].fieldName' value=fieldPermission.fieldName/>
				<#assign prefixIndex = fieldPermission.fieldName?index_of(".")>
				<#if prefixIndex gt 0>
					<span class="fieldTip">(${fieldPermission.fieldName?substring(prefixIndex + 1)})</span>
				</#if>
				<@hidden name='fieldPermissions[' + fieldPermission_index + '].enableFieldPermissionType'/>
			</td>
			<td>
				<@radio name='fieldPermissions[' + fieldPermission_index + '].fieldPermissionType' fieldValue=fn.enums('com.espirit.eap.sa.FieldPermissionType', 'NONE')/>
			</td>
			<td>
				<#assign radioCss = "">
				<#if isSearchMethod || modelPrivilege>
					<#assign radioCss = "display:none">
					<#if fieldPermission.fieldPermissionType == 'NONE'>
						<#assign imgFlag = fn.toInt(fieldPermission.scopeType!0,'scopeType')>
					<#else>
						<#assign imgFlag = fn.toInt(fieldPermission.scopeType!4,'scopeType')>
					</#if>
					<img class="clickStyle" src="${imagePathPrefix}/images/permission/flag${imgFlag}.gif"
								imgFlag="${imgFlag}" onclick="eap_sa_privilege.switchFieldFlag(this)"/>
					<@hidden name='fieldPermissions[' + fieldPermission_index + '].scopeType' value=imgFlag/>
				</#if>
				<@radio name='fieldPermissions[' + fieldPermission_index + '].fieldPermissionType' fieldValue=fn.enums('com.espirit.eap.sa.FieldPermissionType', 'READ') style=radioCss/>
			</td>
			<td>
				<#if fieldPermission.enableFieldPermissionType != 'READ'>
					<#assign radioCss = "">
					<#if modelPrivilege>
						<#assign radioCss = "display:none">
						<#assign imgFlag = fn.toInt(fieldPermission.writeScopeType!4,'writeScopeType')>
						<img class="clickStyle" src="${imagePathPrefix}/images/permission/flag${imgFlag}.gif"
									imgFlag="${imgFlag}" onclick="eap_sa_privilege.switchFieldFlag(this)"/>
						<@hidden name='fieldPermissions[' + fieldPermission_index + '].writeScopeType' value=imgFlag/>
					</#if>			
					<@radio name='fieldPermissions[' + fieldPermission_index + '].fieldPermissionType' fieldValue=fn.enums('com.espirit.eap.sa.FieldPermissionType', 'READWRITE') style=radioCss/>
				</#if>
			</td>
		</tr>
	</#list>
	<#else>
		<tr class="noData"><td colspan=4><@i18n name='pageinfo.noData'/></td></tr>
	</#if>
	</tbody>
</table>

<#if isSearchMethod || modelPrivilege>
<div class="permissionDescription">
	<img src="${imagePathPrefix}/images/permission/flag0.gif"><span>${action.getText('model.espirit.privilege.selectBlank')}</span>
	<img src="${imagePathPrefix}/images/permission/flag1.gif"><span>${action.getText('model.espirit.privilege.selectUser')}</span>
	<img src="${imagePathPrefix}/images/permission/flag2.gif"><span>${action.getText('model.espirit.privilege.selectBizDepart')}</span>
	<img src="${imagePathPrefix}/images/permission/flag3.gif"><span>${action.getText('model.espirit.privilege.selectLeaderBizDepart')}</span>
	<img src="${imagePathPrefix}/images/permission/flag4.gif"><span>${action.getText('model.espirit.privilege.selectOrg')}</span>
</div>
</#if>
</form>

<@container clazz="jcontainer jcontainer-buttonInput" columnCount=100>
	<@button label='action.save' onclick="eap_sa_privilege.saveFieldPrivilege()"/>
	<span style="width: 5px;float: left;">&nbsp;</span>
	<@button label='action.cancel' onclick="eap_sa_privilege.resetFieldPrivilege()"/>
</@container>
</div>